package spring.beanDefinitionRegistryPostProcessor;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Spring 扫描自定义注解：
 *
 * @author ME
 * @date 2021/5/23
 */
public class TestCustomAnnotationScanner {

    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
        context.getBean(CustomBean.class).doSomething();

        try {
            context.getBean(CustomBean2.class).doSomething();
        } catch (BeansException e) {
            System.out.println("CustomBean2 未添加自定义注解，所以不存在 bean。");
        }
    }

    @ComponentScan("spring.beanDefinitionRegistryPostProcessor")
    public static class Config {
    }

}
